home *** CD-ROM | disk | FTP | other *** search
/ Champak Vol K-12 / Vol K-12.iso / interfac / it.dig / scripts / DataProviderSymbol.as next >
Text File  |  2012-08-27  |  3KB  |  101 lines

  1. _global.DataProviderClass = function()
  2. {
  3.    this.init();
  4. };
  5. DataProviderClass.prototype.init = function()
  6. {
  7.    this.items = new Array();
  8.    this.uniqueID = 0;
  9.    this.views = new Array();
  10. };
  11. DataProviderClass.prototype.addView = function(viewRef)
  12. {
  13.    this.views.push(viewRef);
  14.    var _loc2_ = {event:"updateAll"};
  15.    viewRef.modelChanged(_loc2_);
  16. };
  17. DataProviderClass.prototype.addItemAt = function(index, value)
  18. {
  19.    if(index < this.getLength())
  20.    {
  21.       this.items.splice(index,0,"tmp");
  22.    }
  23.    this.items[index] = new Object();
  24.    if(typeof value == "object")
  25.    {
  26.       this.items[index] = value;
  27.    }
  28.    else
  29.    {
  30.       this.items[index].label = value;
  31.    }
  32.    this.items[index].__ID__ = this.uniqueID++;
  33.    var _loc4_ = {event:"addRows",firstRow:index,lastRow:index};
  34.    this.updateViews(_loc4_);
  35. };
  36. DataProviderClass.prototype.addItem = function(value)
  37. {
  38.    this.addItemAt(this.getLength(),value);
  39. };
  40. DataProviderClass.prototype.removeItemAt = function(index)
  41. {
  42.    var _loc4_ = this.items[index];
  43.    this.items.splice(index,1);
  44.    var _loc3_ = {event:"deleteRows",firstRow:index,lastRow:index};
  45.    this.updateViews(_loc3_);
  46.    return _loc4_;
  47. };
  48. DataProviderClass.prototype.removeAll = function()
  49. {
  50.    this.items = new Array();
  51.    this.updateViews({event:"deleteRows",firstRow:0,lastRow:this.getLength() - 1});
  52. };
  53. DataProviderClass.prototype.replaceItemAt = function(index, itemObj)
  54. {
  55.    if(index < 0 || index >= this.getLength())
  56.    {
  57.       return undefined;
  58.    }
  59.    var _loc4_ = this.getItemID(index);
  60.    if(typeof itemObj == "object")
  61.    {
  62.       this.items[index] = itemObj;
  63.    }
  64.    else
  65.    {
  66.       this.items[index].label = itemObj;
  67.    }
  68.    this.items[index].__ID__ = _loc4_;
  69.    this.updateViews({event:"updateRows",firstRow:index,lastRow:index});
  70. };
  71. DataProviderClass.prototype.getLength = function()
  72. {
  73.    return this.items.length;
  74. };
  75. DataProviderClass.prototype.getItemAt = function(index)
  76. {
  77.    return this.items[index];
  78. };
  79. DataProviderClass.prototype.getItemID = function(index)
  80. {
  81.    return this.items[index].__ID__;
  82. };
  83. DataProviderClass.prototype.sortItemsBy = function(fieldName, order)
  84. {
  85.    this.items.sortOn(fieldName);
  86.    if(order == "DESC")
  87.    {
  88.       this.items.reverse();
  89.    }
  90.    this.updateViews({event:"sort"});
  91. };
  92. DataProviderClass.prototype.updateViews = function(eventObj)
  93. {
  94.    var _loc2_ = 0;
  95.    while(_loc2_ < this.views.length)
  96.    {
  97.       this.views[_loc2_].modelChanged(eventObj);
  98.       _loc2_ = _loc2_ + 1;
  99.    }
  100. };
  101.